import 'package:shared_preferences/shared_preferences.dart';
//保存检查登陆状态用的
class SharedPreferencesService {
  static const String adminTokenKey = '';
  static const String tokenKey = '';

  // 保存 JWT Token
  static Future<void> saveToken(String token) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString(tokenKey, token);
  }

  // 保存管理员 JWT Token
  static Future<void> saveAdminToken(String token) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString(adminTokenKey, token);
  }

  // 获取 JWT Token
  static Future<String?> getToken() async {
    final prefs = await SharedPreferences.getInstance();
    return prefs.getString(tokenKey);
  }

  // 获取管理员 JWT Token
  static Future<String?> getAdminToken() async {
    final prefs = await SharedPreferences.getInstance();
    return prefs.getString(adminTokenKey);
  }

  // 清除 JWT Token
  static Future<void> clearToken() async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.remove(tokenKey);
  }
  // 清除管理员 JWT Token
  static Future<void> clearAdminToken() async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.remove(adminTokenKey);
  }
  // 检查用户是否登录
  static Future<bool> isUserLoggedIn() async {
    final token = await getToken();
    return token != null && token.isNotEmpty;
  }
}